package com.jfree.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

public class PostTokenFilter extends ZuulFilter {

    /**
     * 禁用指定的 Filter
     * zuul:
     * SendResponseFilter:
     * post:
     * disable: true
     *
     * @return
     */


    @Override
    public String filterType() {
        return FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return FilterConstants.SEND_RESPONSE_FILTER_ORDER - 1;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("---PostTokenFilter---");
        //int t = 1 / 0;
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletResponse response = requestContext.getResponse();
        response.setHeader("X-FG", UUID.randomUUID().toString());
        return null;
    }
}
